const http=require('http')

const server=http.createServer((req,res)=>{
    res.writeHead(200,{
        'Access-Control-Allow-Origin':'http://127.0.0.1:5500',
        //*表示所有域名都可以访问，也可以指定域名，也可以指定http://127.0.0.1:5500
        'Access-Control-Allow-Methods':'GET,POST',
        'Access-Control-Allow-Headers':'Content-Type',
        'Access-Control-Allow-Credentials':'true'
    })

    //向目标后端发送请求，拿到数据返回给前端
    http.request({
        host:'192.168.1.75',
        port:3000,
        path:'/',
        method:'GET'
    },(proxyRes)=>{
        proxyRes.on('data',(data)=>{
            console.log(data.toString());
            res.end(data.toString())

        })
    }).end()

})
server.listen(3000,()=>{
    console.log('server is running at http://localhost:3000')
})
